﻿namespace ACCOUNTING.LVY.Business
{
    using ACCOUNTING;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Data;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    public class clsXuatKho
    {
        private string mBarCode = "";
        private string mCachTinhChietKhau = "";
        private int mDaIn = 0;
        private double mDaThanhToan = 0.0;
        private double mDaThanhToanNT = 0.0;
        private string mDiaChiGiaoHang = "";
        private string mDiaChiThue = "";
        private string mDienGiai = "";
        private string mDienGiaiGiaoHang = "";
        private string mDuLieu = "NB";
        private int mDuyet = 0;
        private int mGhiSo = 0;
        private int mHanThanhToan = 0;
        private string mHinhThucThanhToan = "";
        private string mKhoa = "";
        private string mKhoaBoPhan = "";
        private string mKhoaDoiTuong = "";
        private string mKhoaDonHang = "";
        private string mKhoaDonVi = "";
        private string mKhoaHopDong = "";
        private string mKhoaKhoanMuc = "";
        private string mKhoaLoaiGia = "";
        private string mKhoaLoaiHoaDon = "";
        private string mKhoaLoaiIn = "";
        private string mKhoaLoaiXuat = "";
        private string mKhoaNhanVienBanHang = "";
        private string mKhoaNhanVienGiaoHang = "";
        private string mKhoaNhanVienSua = "";
        private string mKhoaNhanVienTao = "";
        private string mKhoaSanPham = "";
        private string mKhoaTKChietKhau = "";
        private string mKhoaTKDoanhThu = "";
        private string mKhoaTKThanhToan = "";
        private string mKhoaTKThue = "";
        private string mLoaiBanHang = "";
        private string mLoaiChungTu = "";
        private string mLoaiTien = "";
        private string mMaSoThue = "";
        private string mMauHoaDon = "";
        private string mNgayChungTu = "";
        private string mNgayDonHang = "";
        private string mNgayHoaDon = "";
        private string mNgaySua = "";
        private string mNgayTao = "";
        private string mNgayThanhToan = "";
        private string mNgayThuTien = "";
        private int mNghiepVu = 0;
        private string mNguoiGiao = "";
        private int mSend = 0;
        private string mSoChungTu = "";
        private string mSoDonHang = "";
        private string mSoHoaDon = "";
        private string mSoSeri = "";
        private string mTenDoiTuongThue = "";
        private int mThueSuat = 0;
        private double mThuNgay = 0.0;
        private double mThuNgayNT = 0.0;
        private double mTienChietKhau = 0.0;
        private double mTienChietKhauNT = 0.0;
        private double mTienHang = 0.0;
        private double mTienHangNT = 0.0;
        private double mTienHoaHong = 0.0;
        private double mTienHoaHongNT = 0.0;
        private double mTienThueVAT = 0.0;
        private double mTienThueVATNT = 0.0;
        private double mTienVon = 0.0;
        private double mTienVonNT = 0.0;
        private int mTinhTrangGiaoHang = 0;
        private double mTyGia = 0.0;
        private int mTyLeChietKhau = 0;

        public bool CapNhatGiaVon(string strKhoaDonVi, string strNamThang)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[3];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NamThang", DbType.Int64, ParameterDirection.Input, strNamThang);
                commandParameters[1] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi.Trim());
                commandParameters[2] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_ScanGiaVon", commandParameters);
                flag = Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[2].Value, 0, false);
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public void ClearTemp(string pKeyTable)
        {
            string commandText = "DELETE FROM ST_XuatKhoChiTietTmp WHERE KhoaPhieuXuat = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
            commandText = "DELETE FROM ST_XuatKhoChiTietDichVuTmp WHERE KhoaPhieuXuat = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
            commandText = "DELETE FROM BH_XuatBanChiTietDieuKhoanTmp WHERE KhoaPhieuXuat = '" + pKeyTable.Trim() + "'";
            DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
        }

        public bool DaXuatHoaDon(string strKhoa)
        {
            string commandText = " SELECT top 1 Khoa FROM ST_XuatKhoChiTiet WHERE RTRIM(ISNULL(KhoaHoaDon,'')) <> '' AND KhoaPhieuXuat = '" + strKhoa + "'";
            return (Conversions.ToString(LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing)).Trim() != "");
        }

        public bool DeleteData(string strKhoa, int pLuuThongTin = 1)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[5];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@CheckAK", DbType.Double, ParameterDirection.Input, 1);
                commandParameters[2] = DBHelper.createParameter("@LuuThongTin", DbType.Double, ParameterDirection.Input, pLuuThongTin);
                commandParameters[3] = DBHelper.createParameter("@AmKho", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[4] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_XuatKhoDel", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[4].Value, 0, false))
                {
                    if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[3].Value, 0, false))
                    {
                        LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m kho!", ""));
                    }
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public DataTable GetDataDoanhThuTongHop(string strKhoaDonVi, string strTuNgay, string strDenNgay)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT dbo.Char2Date(XK.NgayChungTu) as Ngay,  Count(XK.SoChungTu) as TongHoaDon, Sum(XK.TienHang) as TienHang,  Sum(XK.TienThueVAT) as TienThue, Sum(XK.TienChietKhau) as TienChietKhau  FROM ST_XuatKho XK WHERE (XK.NgayChungTu Between '" + strTuNgay + "' and '" + strDenNgay + "') And XK.KhoaDonVi = '" + strKhoaDonVi + "' and XK.LoaiChungTu = 'XB' GROUP BY XK.NgayChungTu ORDER BY XK.NgayChungTu";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataHoaDonNoThanhToan(string strKhoaDonVi, string strTinhDenNgay, string strKhoaBaoCao , string strKhoaNhanVien = "")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[5];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@NgayBaoCao", DbType.Int64, ParameterDirection.Input, strTinhDenNgay);
                commandParameters[2] = DBHelper.createParameter("@KhoaBaoCao", DbType.Int64, ParameterDirection.Input, strKhoaBaoCao);
                commandParameters[3] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[4] = DBHelper.createParameter("@KhoaNhanVien", DbType.Int64, ParameterDirection.Input, strKhoaNhanVien);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_ChiTietCongNoPhaiThu", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrint(string strKhoa, string strLanguage = "VIET")
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, UPPER(DT.Ten" + modGeneral.H_LANGUAGE + ") as KhachHang,  DT.DiaChi, DT.Ma as MaKhachHang, DT.MaSoThue, XK.SoHoaDon, dbo.Char2Date(XK.NgayHoaDon) as NgayHoaDon,  XK.SoSeri As Seri, XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, IsNull(HH.Ma,'') as MaHang, RTRIM(HH.Ten" + modGeneral.H_LANGUAGE + ") as TenHang,  RTrim(HH.TenViet) As TenViet, RTrim(HH.TenAnh) As TenAnh,  DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.SoLuong, CT.GiaBanNT as GiaBan, CT.TienBanNT as TienBan, CT.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, CT.TyLeThue, CT.TienThueNT as TienThue, CT.SoSeri , CT.SoLoHang, dbo.Char2Date(CT.HanSuDung) As HanSuDung,  NV.Ten" + modGeneral.H_LANGUAGE + " As NhanVien, NV.DienThoai As DienThoaiNhanVien  FROM ST_XuatKho XK left join ST_XuatKhoChiTiet CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  left join DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  left join DM_DoiTuong NV on XK.KhoaNhanVienBanHang = NV.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "'  UNION ALL  SELECT XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, UPPER(DT.Ten" + modGeneral.H_LANGUAGE + ") as KhachHang,  DT.DiaChi, DT.Ma as MaKhachHang,  DT.MaSoThue, XK.SoHoaDon, dbo.Char2Date(XK.NgayHoaDon) as NgayHoaDon,  XK.SoSeri, XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, '',  IsNull(CT.TenDichVu,'') as TenHang,  CT.TenDichVu, CT.TenDichVu,  '' as DonViTinh,  CT.SoLuong, CT.DonGiaNT as DonGia, CT.TienBanNT As TienBan, CT.TyLeChietKhau, CT.TienChietKhauNT as TienChietKhau,  CT.TyLeThue, CT.TienThueNT as TienThue, '', '', '', NV.Ten" + modGeneral.H_LANGUAGE + " As NhanVien, NV.DienThoai As DienThoaiNhanVien   FROM ST_XuatKho XK left join ST_XuatKhoChiTietDichVu CT on XK.Khoa = CT.KhoaPhieuXuat   left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa   left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa   left join DM_DoiTuong NV on XK.KhoaNhanVienBanHang = NV.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                DataTable table2 = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
                int index = 0;
                while (index <= (table2.Rows.Count - 1))
                {
                    if (LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(table2.Rows[index]["TenHang"]), "", modGeneral.TypeOfValue.Nothing).ToString().Trim() == "")
                    {
                        table2.Rows.RemoveAt(index);
                    }
                    else
                    {
                        index++;
                    }
                }
                table = table2;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrint_Mau(int intLien, string strMauHD, string strKiHieu)
        {
            DataTable table;
            try
            {
                string str2 = "SELECT TOP  " + Conversions.ToString(intLien) + " * FROM HT_DSLien ORDER BY Khoa";
                string commandText = "  SELECT '' as MaHang, '" + strMauHD + "' as MauHoaDon, '" + strKiHieu + "' as SoSeri, '0000000' as SoHoaDon ";
                commandText = "SELECT A.*, B.TenViet as TenLienViet, B.DienGiaiViet as DienGiaiLienViet, B.TenAnh as TenLienAnh, B.DienGiaiAnh as DienGiaiLienAnh FROM (" + commandText + ") A CROSS JOIN (" + str2 + ") B";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintBangKeTraHangNCC(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaDoiTuong)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, strKhoaDoiTuong);
                commandParameters[4] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_BangKeTraHangNCC", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintBangKeXuatKhoTH(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaLoaiXuat, int intXuatBan = 0)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaLoaiXuat", DbType.Int64, ParameterDirection.Input, strKhoaLoaiXuat);
                commandParameters[4] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[5] = DBHelper.createParameter("@HienThi", DbType.Int64, ParameterDirection.Input, "TH");
                commandParameters[6] = DBHelper.createParameter("@XuatBan", DbType.Double, ParameterDirection.Input, intXuatBan);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_BC_BangKePhieuXuatKho", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintBienBan(string strKhoa, string strLanguage = "VIET")
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT DT.TenViet As KhachHang, DT.DiaChi, DT.DienThoai, \t GH.DiaChiGiaoHang, GH.DienGiaiGiaoHang, GH.NguoiGiao as DaiDienBenNhan, GH.SoDonHang,  HH.Ma as MaHang, HH.TenViet as TenHang, HH.ThongSoKyThuat as QuyCach,  DVT.TenViet as DonViTinh, CT.SoLuong, dbo.Char2Date(GH.NgayChungTu) as NgayGiao  FROM ST_XuatKho GH  LEFT JOIN DM_DoiTuong DT on GH.KhoaDoiTuong = DT.Khoa  LEFT JOIN ST_XuatKhoChiTiet CT on GH.Khoa = CT.KhoaPhieuXuat  LEFT JOIN DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  WHERE GH.Khoa = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintDK(string strKhoa, string strLanguage)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT DK.NoiDung" + strLanguage + ", DKBG.Ten" + strLanguage + " as DKBaoGia, DK.HienThi  FROM BH_XuatBanChiTietDieuKhoan DK   LEFT JOIN DM_DieuKhoanBaoGia DKBG on DK.KhoaDieuKhoan = DKBG.Khoa  WHERE DK.KhoaPhieuXuat = '" + strKhoa + "' order by DK.STT ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintDoanhThuTheoKH(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaBaoCao, string strLoaiBaoCao)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaBaoCao", DbType.Int64, ParameterDirection.Input, strKhoaBaoCao);
                commandParameters[4] = DBHelper.createParameter("@strLoaiKhac", DbType.Int64, ParameterDirection.Input, modGeneral.Tranlated("Loại kh\x00e1c", ""));
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[6] = DBHelper.createParameter("@LoaiBaoCao", DbType.Int64, ParameterDirection.Input, strLoaiBaoCao);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_BangKeDoanhThuTheoLoaiKH", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintDoanhThuTheoKhuVuc(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaKhuVuc, string strLoai)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaKhuVuc", DbType.Int64, ParameterDirection.Input, strKhoaKhuVuc);
                commandParameters[4] = DBHelper.createParameter("@strLoaiKhac", DbType.Int64, ParameterDirection.Input, modGeneral.Tranlated("Kh\x00e1c", ""));
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[6] = DBHelper.createParameter("@LoaiBaoCao", DbType.Int64, ParameterDirection.Input, strLoai);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_DoanhThuTheoKhuVuc", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintHoaDon(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaBC, string strLoaiBC)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[6];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoaBC);
                commandParameters[4] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[5] = DBHelper.createParameter("@LoaiBC", DbType.Int64, ParameterDirection.Input, strLoaiBC);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_BangKeHoaDonBanHang", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintHoaDonBanHangCoCK(string strKhoaDonVi, string strTuNgay, string strDenNgay)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_BangKeHoaDonCoChietKhau", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintHoaDonDenHanThanhToan(string strKhoaDonVi, string strNgayToiHan, string strKhoaBaoCao, string strKhoaTaiKhoan, int IntLoai, string strKhoaNhanVien = "")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@KhoaBaoCao", DbType.Int64, ParameterDirection.Input, strKhoaBaoCao);
                commandParameters[2] = DBHelper.createParameter("@KhoaTaiKhoan", DbType.Int64, ParameterDirection.Input, strKhoaTaiKhoan);
                commandParameters[3] = DBHelper.createParameter("@NgayToiHan", DbType.Int64, ParameterDirection.Input, strNgayToiHan);
                commandParameters[4] = DBHelper.createParameter("@CachIn", DbType.Int64, ParameterDirection.Input, IntLoai);
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[6] = DBHelper.createParameter("@KhoaNhanVien", DbType.Int64, ParameterDirection.Input, strKhoaNhanVien);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_HoaDonDenHanThanhToan", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintHoaDonDichVu(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaBC, string strLoaiBC)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[6];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, strKhoaBC);
                commandParameters[4] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[5] = DBHelper.createParameter("@LoaiBC", DbType.Int64, ParameterDirection.Input, strLoaiBC);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BH_BC_BangKeHoaDonBanHangDichVu", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintMP(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, UPPER(DT.Ten" + modGeneral.H_LANGUAGE + ") as KhachHang,  DT.DiaChi, DT.Ma as MaKhachHang, DT.MaSoThue, XK.SoHoaDon, dbo.Char2Date(XK.NgayHoaDon) as NgayHoaDon,  XK.SoSeri, XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, HH.Ma as MaHang, RTRIM(HH.Ten" + modGeneral.H_LANGUAGE + ") as TenHang,  RTrim(HH.TenViet) As TenViet, RTrim(HH.TenAnh) As TenAnh,  Rtrim(DVT.Ten" + modGeneral.H_LANGUAGE + ") + ' ' + HH.KichThuoc as DonViTinh, CT.SoLuong, CT.GiaBanNT as GiaBan, CT.TienBanNT as TienBan, CT.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, CT.TyLeThue, CT.TienThueNT as TienThue, CT.SoLoHang, dbo.Char2Date(CT.HanSuDung) As HanSuDung,  NV.Ten" + modGeneral.H_LANGUAGE + " As NhanVien, NV.DienThoai As DienThoaiNhanVien  FROM ST_XuatKho XK left join ST_XuatKhoChiTiet CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  left join DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  left join DM_DoiTuong NV on XK.KhoaNhanVienBanHang = NV.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintNhapKho(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaDoiTuong)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[5];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[4] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_BangKePhieuNhapKho", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintPhieuXuat(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu, DT.Ten" + modGeneral.H_LANGUAGE + " as KhachHang,  DT.DiaChi as DiaChi, DT.Ma as MaKhachHang, DT.MaSoThue, XK.SoHoaDon, dbo.Char2Date(XK.NgayHoaDon) as NgayHoaDon,  XK.SoSeri, XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, HH.Ma as MaHang, HH.Ten" + modGeneral.H_LANGUAGE + " as TenHang,  DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.SoLuong, CT.GiaVonNT as GiaBan, CT.TienVonNT as TienBan, CT.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, CT.TyLeThue, CT.TienThueNT as TienThue  FROM ST_XuatKho XK left join ST_XuatKhoChiTiet CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  left join DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintTheoDoiKyGuiDaiLy(string strTuNgay, string strDenNgay, string strKhoaDonVi)
        {
            DataTable table;
            try
            {
                string commandText = "  SELECT DT.TenViet as TenKhachHang, HH.Ma as MaHang, HH.TenViet as TenHang, DVT.TenViet as DonViTinh, IsNull(SoLuongTonDau,0) as SoLuongTonDau, IsNull(TriGiaTonDau,0) as TriGiaTonDau, IsNull(SoLuongDaGiao,0) as SoLuongDaGiao,  IsNull(TriGiaDaGiao,0) as TriGiaDaGiao, IsNull(SoLuongXuat,0) as SoLuongXuat, IsNull(TriGiaXuat,0) as TriGiaXuat, IsNull(SoLuongTonDau,0)+IsNull(SoLuongDaGiao,0)-IsNull(SoLuongXuat,0) as SoLuongTonCuoi,  IsNull(TriGiaTonDau,0)+IsNull(TriGiaDaGiao,0)-IsNull(TriGiaXuat,0) as TriGiaTonCuoi  FROM ST_TheoDoiKyGoiDaiLy KG  LEFT JOIN DM_DoiTuong DT on KG.KhoaKhachHang = DT.Khoa  LEFT JOIN DM_HangHoa HH on KG.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on KG.KhoaDonViTinh = DVT.Khoa  WHERE KG.NamThang BETWEEN '" + Strings.Left(strTuNgay, 6) + "' AND '" + Strings.Left(strDenNgay, 6) + "' AND KG.KhoaDonVi = '" + strKhoaDonVi + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintTheoDoiKyGuiDaiLy_ChiTiet(string strTuNgay, string strDenNgay, string strKhoaDonVi)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, Strings.Left(strTuNgay, 6));
                commandParameters[1] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, Strings.Left(strDenNgay, 6));
                commandParameters[2] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[3] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_TheoDoiKyGoiDaiLy", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintTinhHinhSuDungHoaDon(string strNgayThang1, string strNgayThang2)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[2];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@NgayThang1", DbType.Int64, ParameterDirection.Input, Strings.Left(strNgayThang1, 6));
                commandParameters[1] = DBHelper.createParameter("@NgayThang2", DbType.Int64, ParameterDirection.Input, Strings.Left(strNgayThang2, 6));
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_TinhHinhSuDungHoaDon", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintVAT(string strKhoa, int intLien)
        {
            DataTable table;
            try
            {
                string str2 = "SELECT TOP  " + Conversions.ToString(intLien) + " * FROM HT_DSLien ORDER BY Khoa";
                string commandText = "  SELECT XK.HinhThucThanhToan, XK.MauHoaDon , XK.NguoiGiao, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, UPPER(XK.TenDoiTuongThue) as KhachHang,  XK.DiaChiThue as DiaChi, DT.Ma as MaKhachHang, XK.MaSoThue, XK.SoHoaDon, dbo.Char2Date(XK.NgayHoaDon) as NgayHoaDon,  XK.SoSeri, XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, HH.Ma as MaHang, RTRIM(HH.Ten" + modGeneral.H_LANGUAGE + ") as TenHang,  DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.SoLuong, CT.GiaBanNT as GiaBan, CT.TienBanNT as TienBan, XK.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, XK.ThueSuat as TyLeThue, CT.TienThueNT as TienThue  FROM ST_XuatKho XK left join ST_XuatKhoChiTiet CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  left join DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                commandText = "SELECT A.*, B.TenViet as TenLienViet, B.DienGiaiViet as DienGiaiLienViet, B.TenAnh as TenLienAnh, B.DienGiaiAnh as DienGiaiLienAnh FROM (" + commandText + ") A CROSS JOIN (" + str2 + ") B";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintVAT_XemThu(string strKhoa, int intLien, string strSelect)
        {
            DataTable table;
            try
            {
                string str2 = "SELECT TOP  " + Conversions.ToString(intLien) + " * FROM HT_DSLien ORDER BY Khoa";
                string commandText = "  SELECT XK.NguoiGiao, XK.HinhThucThanhToan, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, " + strSelect + " XK.DiaChiThue as DiaChi, DT.Ma as MaKhachHang,  XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, HH.Ma as MaHang, RTRIM(HH.Ten" + modGeneral.H_LANGUAGE + ") as TenHang,  DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.SoLuong, CT.GiaBanNT as GiaBan, CT.TienBanNT as TienBan, XK.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, XK.ThueSuat as TyLeThue, CT.TienThueNT as TienThue  FROM ST_XuatKho XK left join ST_XuatKhoChiTiet CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  left join DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                commandText = "SELECT A.*, B.TenViet as TenLienViet, B.DienGiaiViet as DienGiaiLienViet, B.TenAnh as TenLienAnh, B.DienGiaiAnh as DienGiaiLienAnh FROM (" + commandText + ") A CROSS JOIN (" + str2 + ") B";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintVATDichVu(string strKhoa, int intLien)
        {
            DataTable table;
            try
            {
                string str2 = "SELECT TOP  " + Conversions.ToString(intLien) + " * FROM HT_DSLien ORDER BY Khoa";
                string commandText = "  SELECT XK.HinhThucThanhToan, XK.MauHoaDon , XK.NguoiGiao, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, UPPER(XK.TenDoiTuongThue) as KhachHang,  XK.DiaChiThue as DiaChi, DT.Ma as MaKhachHang, XK.MaSoThue, XK.SoHoaDon, dbo.Char2Date(XK.NgayHoaDon) as NgayHoaDon,  XK.SoSeri, XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, '' as MaHang, RTRIM(CT.TenDichVu) as TenHang,  '' as DonViTinh, 1.00 as SoLuong, CT.TienBanNT as GiaBan, CT.TienBanNT as TienBan, XK.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, XK.ThueSuat as TyLeThue, CT.TienThueNT as TienThue  FROM ST_XuatKho XK left join ST_XuatKhoChiTietDichVu CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                commandText = "SELECT A.*, B.TenViet as TenLienViet, B.DienGiaiViet as DienGiaiLienViet, B.TenAnh as TenLienAnh, B.DienGiaiAnh as DienGiaiLienAnh FROM (" + commandText + ") A CROSS JOIN (" + str2 + ") B";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintVATDichVu_XemThu(string strKhoa, int intLien, string strSelect)
        {
            DataTable table;
            try
            {
                string str2 = "SELECT TOP  " + Conversions.ToString(intLien) + " * FROM HT_DSLien ORDER BY Khoa";
                string commandText = "  SELECT XK.NguoiGiao, XK.HinhThucThanhToan, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as NgayChungTu,XK.LoaiTien, XK.TyGia, " + strSelect + " XK.DiaChiThue as DiaChi, DT.Ma as MaKhachHang,  XK.TienHangNT as TongTienHang, XK.TienChietKhauNT as TongTienChietKhau,  XK.TienThueVATNT as TongTienThueVAT, TK.SoTaiKhoan, XK.DienGiaiGiaoHang as DienGiai, '' as MaHang, RTRIM(CT.TenDichVu) as TenHang,  '' as DonViTinh, 1.00 as SoLuong, CT.TienBanNT as GiaBan, CT.TienBanNT as TienBan, XK.TyLeChietKhau,   CT.TienChietKhauNT as TienChietKhau, XK.ThueSuat as TyLeThue, CT.TienThueNT as TienThue  FROM ST_XuatKho XK left join ST_XuatKhoChiTietDichVu CT on XK.Khoa = CT.KhoaPhieuXuat  left join DM_DoiTuong DT on XK.KhoaDoiTuong = DT.Khoa  left join DM_TaiKhoan TK on XK.KhoaTKThanhToan = TK.Khoa  WHERE XK.Khoa = '" + strKhoa.Trim() + "' ";
                commandText = "SELECT A.*, B.TenViet as TenLienViet, B.DienGiaiViet as DienGiaiLienViet, B.TenAnh as TenLienAnh, B.DienGiaiAnh as DienGiaiLienAnh FROM (" + commandText + ") A CROSS JOIN (" + str2 + ") B";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataPrintXuatKhoCT(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaLoaiXuat, int intXuatBan = 0)
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[7];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaLoaiXuat", DbType.Int64, ParameterDirection.Input, strKhoaLoaiXuat);
                commandParameters[4] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, modGeneral.H_LANGUAGE);
                commandParameters[5] = DBHelper.createParameter("@HienThi", DbType.Int64, ParameterDirection.Input, "CT");
                commandParameters[6] = DBHelper.createParameter("@XuatBan", DbType.Double, ParameterDirection.Input, intXuatBan);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_BC_BangKePhieuXuatKho", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDataTongHopThuTienBanHang(string strKhoaDonVi, int strTuNgay, string strDenNgay, string strKhoaDoiTuong = "")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[4];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, strKhoaDoiTuong);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_TongHopThuTienBanHang", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDetailDichVu(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaTKDoanhThu As KhoaTaiKhoan, TK.SoTaiKhoan, CT.TenDichVu, CT.MaDichVu, CT.KhoaDichVu, CT.SoLuong,  CT.DonGiaNT, CT.TienBanNT, CT.TyLeChietKhau, CT.TienChietKhauNT, CT.TyLeThue, CT.TienThueNT  FROM  ST_XuatKhoChiTietDichVu CT LEFT JOIN DM_TaiKhoan TK ON CT.KhoaTKDoanhThu = TK.Khoa  WHERE CT.KhoaPhieuXuat = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDetailsTraHang(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaKho, K.Ten" + modGeneral.H_LANGUAGE + " as KhoHang, CT.KhoaHangHoa, HH.Ma, HH.Ten" + modGeneral.H_LANGUAGE + " as HangHoa,  CT.SoLoHang, CT.SoSeri, CT.NgayNhap, CT.HanSuDung , CT.KhoaDonViTinh, DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.QuyCach, CT.SoLuong, CT.GiaBanNT, CT.TienBanNT, CT.TyLeChietKhau,  CT.TienChietKhauNT, CT.TyLeThue, CT.TienThueNT,  CT.KhoaTKHangHoa, TK.SoTaiKhoan as TaiKhoanHangHoa,  CT.KhoaTKGiaVon, GV.SoTaiKhoan as TaiKhoanGiaVon, CT.GiaBanNT, CT.TienBanNT  FROM ST_XuatKhoChiTiet CT LEFT JOIN DM_Kho K on CT.KhoaKho = K.Khoa  LEFT JOIN DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_TaiKhoan TK on CT.KhoaTKHangHoa = TK.Khoa  LEFT JOIN DM_TaiKhoan GV on CT.KhoaTKGiaVon = GV.Khoa  WHERE CT.KhoaPhieuXuat = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetDieuKhoan(string pKhoa)
        {
            string commandText = "SELECT CT.Khoa, CT.KhoaDieuKhoan, DK.Ten" + modGeneral.H_LANGUAGE + " as DieuKhoan, CT.NoiDungViet, CT.NoiDungAnh, CT.HienThi  FROM BH_XuatBanChiTietDieuKhoan CT left join DM_DieuKhoanBaoGia DK on CT.KhoaDieuKhoan = DK.Khoa  WHERE CT.KhoaPhieuXuat = '" + pKhoa + "' ORDER BY CT.Khoa";
            return DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
        }

        public DataTable GetDoanhThuTheoMatHang(string strKhoaDonVi, string strTuNgay, string strDenNgay, string strKhoaBaoCao, string strKhoaNhom, string strlanguage = "VIET")
        {
            DataTable table;
            IDataParameter[] commandParameters = new IDataParameter[6];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, strKhoaDonVi);
                commandParameters[1] = DBHelper.createParameter("@TuNgay", DbType.Int64, ParameterDirection.Input, strTuNgay);
                commandParameters[2] = DBHelper.createParameter("@DenNgay", DbType.Int64, ParameterDirection.Input, strDenNgay);
                commandParameters[3] = DBHelper.createParameter("@KhoaBaoCao", DbType.Int64, ParameterDirection.Input, strKhoaBaoCao);
                commandParameters[4] = DBHelper.createParameter("@KhoaNhom", DbType.Int64, ParameterDirection.Input, strKhoaNhom);
                commandParameters[5] = DBHelper.createParameter("@Language", DbType.Int64, ParameterDirection.Input, strlanguage);
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.StoredProcedure, "BC_sp_DoanhThuTheoMatHang", commandParameters).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetHangHoaTonKho(string NamThang, string KhoaKho = "", string KhoaNhom = "", string KhoaLoaiGia = "", string strOrder = "")
        {
            DataTable table;
            string str3 = "";
            try
            {
                string str;
                string str2;
                str3 = " And TK.NamThang = '" + NamThang + "'";
                if (KhoaKho.Trim() != "")
                {
                    str3 = str3 + " And TK.KhoaKho = '" + KhoaKho + "'";
                }
                if (KhoaNhom.Trim() != "")
                {
                    str3 = str3 + " And HH.KhoaNhom = '" + KhoaNhom + "'";
                }
                switch (modGeneral.H_LOAIGIA)
                {
                    case "A":
                    case "F":
                        str = " ORDER BY TK.NgayNhap DESC, HH.Ma";
                        break;

                    case "L":
                        str = " ORDER BY TK.NgayNhap , HH.Ma";
                        break;
                }
                if (KhoaLoaiGia == "")
                {
                    str2 = "SELECT TK.KhoaKho, TK.KhoaHangHoa, HH.Ma, HH.Ten" + modGeneral.H_LANGUAGE + " as HangHoa, TK.SoSeri,  TK.SoLoHang, dbo.Char2Date(TK.NgayNhap) as NgayNhap, dbo.Char2Date(TK.HanSuDung) as HanSuDung, DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh,  IsNull(TK.SoLuongTonDau,0) + IsNull(TK.SoLuongNhap,0) - IsNull(SoLuongXuat,0) as SoLuongTon, IsNull(TK.TriGiaTonDau,0) + IsNull(TK.TriGiaNhap, 0) - IsNull(TK.TriGiaXuat,0) as TriGiaTon, TK.DonGia,  IsNull(GB.GiaBan,0) as GiaBan  FROM ST_TonKhoDauKy TK left join DM_HangHoa HH on TK.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on HH.KhoaDonViTinh = DVT.Khoa  LEFT JOIN BH_GiaBan GB on HH.Khoa = GB.KhoaHangHoa and GB.GiaChuan = 1  Where IsNull(TK.SoLuongTonDau,0) + IsNull(TK.SoLuongNhap,0) - IsNull(SoLuongXuat,0) > 0  " + str3 + " ORDER BY 3";
                }
                else
                {
                    str2 = "SELECT TK.KhoaKho, TK.KhoaHangHoa, HH.Ma, HH.Ten" + modGeneral.H_LANGUAGE + " as HangHoa, TK.SoSeri,  TK.SoLoHang, dbo.Char2Date(TK.NgayNhap) as NgayNhap, dbo.Char2Date(TK.HanSuDung) as HanSuDung, DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh,  IsNull(TK.SoLuongTonDau,0) + IsNull(TK.SoLuongNhap,0) - IsNull(SoLuongXuat,0) as SoLuongTon, IsNull(TK.TriGiaTonDau,0) + IsNull(TK.TriGiaNhap, 0) - IsNull(TK.TriGiaXuat,0) as TriGiaTon, TK.DonGia,  IsNull(GB.GiaBan,0) as GiaBan  FROM ST_TonKhoDauKy TK left join DM_HangHoa HH on TK.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on HH.KhoaDonViTinh = DVT.Khoa  LEFT JOIN BH_GiaBan GB on HH.Khoa = GB.KhoaHangHoa and GB.KhoaLoaiGia = '" + KhoaLoaiGia + "' Where IsNull(TK.SoLuongTonDau,0) + IsNull(TK.SoLuongNhap,0) - IsNull(SoLuongXuat,0) > 0  " + str3 + " ORDER BY 3";
                }
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, str2, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public string GetKhoaHoaDon(string strCondition = "")
        {
            string str;
            string str3 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str3 = " WHERE " + strCondition;
                }
                string commandText = "SELECT XK.Khoa FROM ST_XuatKho XK" + str3 + " ORDER BY XK.NgayChungTu, XK.SoChungTu";
                str = Conversions.ToString(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]));
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                str = "";
                ProjectData.ClearProjectError();
                return str;
                ProjectData.ClearProjectError();
            }
            return str;
        }

        public DataTable GetList(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT XK.Khoa, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as Ngay, XK.SoHoaDon, XK.SoSeri, DT.Ten" + modGeneral.H_LANGUAGE + " as NhaCungCap,  XK.TienHang , XK.TienChietKhau,  XK.TienThueVAT as TienThue, XK.GhiSo, LI.LoaiIn, XK.DaIn FROM ST_XuatKho XK LEFT JOIN HT_LoaiIn LI ON XK.KhoaLoaiIn = LI.Khoa LEFT JOIN DM_DoiTuong DT ON XK.KhoaDoiTuong = DT.Khoa " + str2 + " ORDER BY XK.NgayChungTu, XK.SoChungTu";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListDetails(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaKho, K.Ma as KhoHang, CT.KhoaHangHoa, HH.Ma, HH.Ten" + modGeneral.H_LANGUAGE + " as HangHoa,  CT.SoLoHang, CT.SoSeri, CT.NgayNhap, CT.HanSuDung, CT.KhoaDonViTinh, DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.QuyCach, CT.SoLuong, CT.GiaBanNT, CT.TienBanNT, CT.TyLeChietKhau,  CT.TienChietKhauNT, CT.TyLeThue, CT.TienThueNT, CT.TienThue, CT.GiaVon, CT.TienVon,  CT.KhoaTKHangHoa, TK.SoTaiKhoan as TaiKhoanHangHoa,  CT.KhoaTKGiaVon, TKV.SoTaiKhoan as TaiKhoanGiaVon, CT.Loai, CT.KhoaChiTiet, CT.KhoaHoaDon  FROM ST_XuatKhoChiTiet CT LEFT JOIN DM_Kho K on CT.KhoaKho = K.Khoa  LEFT JOIN DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_TaiKhoan TK on CT.KhoaTKHangHoa = TK.Khoa  LEFT JOIN DM_TaiKhoan TKV on CT.KhoaTKGiaVon = TKV.Khoa  WHERE CT.KhoaPhieuXuat = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListDetailsHuy(string strKhoa)
        {
            DataTable table;
            try
            {
                string commandText = " SELECT CT.Khoa, CT.KhoaKho, K.Ma as KhoHang, CT.KhoaHangHoa, HH.Ma, HH.Ten" + modGeneral.H_LANGUAGE + " as HangHoa,  CT.SoLoHang, CT.SoSeri, CT.NgayNhap, CT.HanSuDung, CT.KhoaDonViTinh, DVT.Ten" + modGeneral.H_LANGUAGE + " as DonViTinh, CT.QuyCach, CT.SoLuong, CT.GiaBanNT, CT.TienBanNT, CT.TyLeChietKhau,  CT.TienChietKhauNT, CT.TyLeThue, CT.TienThueNT, CT.GiaVon, CT.TienVon,  CT.KhoaTKHangHoa, TK.SoTaiKhoan as TaiKhoanHangHoa,  CT.KhoaTKGiaVon, TKV.SoTaiKhoan as TaiKhoanGiaVon, CT.Loai, CT.KhoaChiTiet, CT.KhoaHoaDon  FROM ST_XuatKhoChiTietDel CT LEFT JOIN DM_Kho K on CT.KhoaKho = K.Khoa  LEFT JOIN DM_HangHoa HH on CT.KhoaHangHoa = HH.Khoa  LEFT JOIN DM_DonViTinh DVT on CT.KhoaDonViTinh = DVT.Khoa  LEFT JOIN DM_TaiKhoan TK on CT.KhoaTKHangHoa = TK.Khoa  LEFT JOIN DM_TaiKhoan TKV on CT.KhoaTKGiaVon = TKV.Khoa  WHERE CT.KhoaPhieuXuat = '" + strKhoa + "'";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListHuy(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT XK.Khoa, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as Ngay, XK.SoHoaDon, XK.SoSeri, DT.Ten" + modGeneral.H_LANGUAGE + " as NhaCungCap,  XK.TienHang , XK.TienChietKhau,  XK.TienThueVAT as TienThue, XK.GhiSo FROM ST_XuatKhoDel XK LEFT JOIN DM_DoiTuong DT ON XK.KhoaDoiTuong = DT.Khoa " + str2 + " ORDER BY XK.NgayChungTu, XK.SoChungTu";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public DataTable GetListXuatKho(string strCondition = "")
        {
            DataTable table;
            string str2 = "";
            try
            {
                if (strCondition.Trim() != "")
                {
                    str2 = " WHERE " + strCondition;
                }
                string commandText = "SELECT XK.Khoa, XK.SoChungTu, dbo.Char2Date(XK.NgayChungTu) as Ngay, TK.SoTaiKhoan,  XK.TienHangNT - XK.TienChietKhauNT + XK.TienThueVATNT as SoTienNT, XK.TienHang - XK.TienChietKhau + XK.TienThueVAT as SoTien, XK.DienGiai,XK.GhiSo FROM ST_XuatKho XK LEFT JOIN DM_TaiKhoan TK ON XK.KhoaTKThanhToan = TK.Khoa " + str2 + " ORDER BY XK.NgayChungTu, XK.SoChungTu ";
                table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                table = null;
                ProjectData.ClearProjectError();
                return table;
                ProjectData.ClearProjectError();
            }
            return table;
        }

        public void GetSoTaiKhoan(string strKhoa, ref string strTKNo, ref string strTKCo)
        {
            string commandText = "";
            clsDMTaiKhoan khoan = new clsDMTaiKhoan();
            int num = 0;
            try
            {
                this.Load(strKhoa);
                khoan.Load(LVYModule.ReturnIfNull(this.mKhoaTKThanhToan, "", modGeneral.TypeOfValue.Nothing).ToString().Trim());
                if (this.mGhiSo == 0)
                {
                    strTKNo = "";
                    strTKCo = "";
                }
                else
                {
                    strTKNo = LVYModule.ReturnIfNull(khoan.SoTaiKhoan, "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                    if (this.mLoaiChungTu == "XK")
                    {
                        commandText = "SELECT Distinct(SoTaiKhoan) SoTaiKhoan FROM DM_TaiKhoan Where Khoa in (Select KhoaTKHangHoa  FROM ST_XuatKhoChiTiet Where KhoaPhieuXuat = '" + strKhoa + "' )";
                        DataTable table = DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0];
                        int num2 = table.Rows.Count - 1;
                        for (num = 0; num <= num2; num++)
                        {
                            if (strTKCo.Trim() != "")
                            {
                                strTKCo = Conversions.ToString(Microsoft.VisualBasic.CompilerServices.Operators.ConcatenateObject(strTKCo.Trim() + ",", table.Rows[num]["SoTaiKhoan"]));
                            }
                            else
                            {
                                strTKCo = Conversions.ToString(table.Rows[num]["SoTaiKhoan"]);
                            }
                        }
                    }
                    if (this.mLoaiChungTu == "XB")
                    {
                        khoan.Load(LVYModule.ReturnIfNull(this.mKhoaTKDoanhThu, "", modGeneral.TypeOfValue.Nothing).ToString().Trim());
                        strTKCo = LVYModule.ReturnIfNull(khoan.SoTaiKhoan, "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                        khoan.Load(LVYModule.ReturnIfNull(this.mKhoaTKThue, "", modGeneral.TypeOfValue.Nothing).ToString().Trim());
                        if (strTKCo.Trim() != "")
                        {
                            strTKCo = strTKCo.Trim() + "," + LVYModule.ReturnIfNull(khoan.SoTaiKhoan, "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                        }
                        else
                        {
                            strTKCo = LVYModule.ReturnIfNull(khoan.SoTaiKhoan, "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
                        }
                    }
                }
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message);
                ProjectData.ClearProjectError();
            }
        }

        public bool IsDuplicateVoucherNo(string strVoucherNo, string strKeyTable)
        {
            string commandText = "SELECT * FROM ST_XuatKho Where Rtrim(SoChungTu) = '" + strVoucherNo.Trim() + "' AND Khoa <> '" + strKeyTable + "'";
            return (DBHelper.ExecuteDataset(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]).Tables[0].Rows.Count > 0);
        }

        public bool Load(string pKhoa)
        {
            bool flag=false;
            try
            {
                string commandText = "SELECT * FROM ST_XuatKho WHERE Khoa = '" + pKhoa + "'";
                IDataReader dataReader = DBHelper.ExecuteReader(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0]);
                if (dataReader.Read())
                {
                    this.mKhoa = Conversions.ToString(modGeneral.GetValue(dataReader, 0, modGeneral.typeOfColumn.GetString));
                    this.mKhoaLoaiXuat = Conversions.ToString(modGeneral.GetValue(dataReader, 1, modGeneral.typeOfColumn.GetString));
                    this.mKhoaKhoanMuc = Conversions.ToString(modGeneral.GetValue(dataReader, 2, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDonHang = Conversions.ToString(modGeneral.GetValue(dataReader, 3, modGeneral.typeOfColumn.GetString));
                    this.mSoDonHang = Conversions.ToString(modGeneral.GetValue(dataReader, 4, modGeneral.typeOfColumn.GetString));
                    this.mNgayDonHang = Conversions.ToString(modGeneral.GetValue(dataReader, 5, modGeneral.typeOfColumn.GetString));
                    this.mSoChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 6, modGeneral.typeOfColumn.GetString));
                    this.mNgayChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 7, modGeneral.typeOfColumn.GetString));
                    this.mKhoaDoiTuong = Conversions.ToString(modGeneral.GetValue(dataReader, 8, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienBanHang = Conversions.ToString(modGeneral.GetValue(dataReader, 9, modGeneral.typeOfColumn.GetString));
                    this.mKhoaLoaiGia = Conversions.ToString(modGeneral.GetValue(dataReader, 10, modGeneral.typeOfColumn.GetString));
                    this.mNguoiGiao = Conversions.ToString(modGeneral.GetValue(dataReader, 11, modGeneral.typeOfColumn.GetString));
                    this.mKhoaBoPhan = Conversions.ToString(modGeneral.GetValue(dataReader, 12, modGeneral.typeOfColumn.GetString));
                    this.mKhoaSanPham = Conversions.ToString(modGeneral.GetValue(dataReader, 13, modGeneral.typeOfColumn.GetString));
                    this.mKhoaHopDong = Conversions.ToString(modGeneral.GetValue(dataReader, 14, modGeneral.typeOfColumn.GetString));
                    this.mLoaiTien = Conversions.ToString(modGeneral.GetValue(dataReader, 15, modGeneral.typeOfColumn.GetString));
                    this.mTyGia = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x10, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaLoaiHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 0x11, modGeneral.typeOfColumn.GetString));
                    this.mThueSuat = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x12, modGeneral.typeOfColumn.GetInt32));
                    this.mSoHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 0x13, modGeneral.typeOfColumn.GetString));
                    this.mNgayHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 20, modGeneral.typeOfColumn.GetString));
                    this.mSoSeri = Conversions.ToString(modGeneral.GetValue(dataReader, 0x15, modGeneral.typeOfColumn.GetString));
                    this.mTienHangNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x16, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienHang = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x17, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienChietKhauNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x18, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienChietKhau = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x19, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThueVATNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x1a, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienThueVAT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x1b, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaTKThanhToan = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1c, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKThue = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1d, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKDoanhThu = Conversions.ToString(modGeneral.GetValue(dataReader, 30, modGeneral.typeOfColumn.GetString));
                    this.mKhoaTKChietKhau = Conversions.ToString(modGeneral.GetValue(dataReader, 0x1f, modGeneral.typeOfColumn.GetString));
                    this.mDienGiai = Conversions.ToString(modGeneral.GetValue(dataReader, 0x20, modGeneral.typeOfColumn.GetString));
                    this.mHanThanhToan = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x21, modGeneral.typeOfColumn.GetInt32));
                    this.mNgayThanhToan = Conversions.ToString(modGeneral.GetValue(dataReader, 0x22, modGeneral.typeOfColumn.GetString));
                    this.mDaThanhToanNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x23, modGeneral.typeOfColumn.GetDecimal));
                    this.mDaThanhToan = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x24, modGeneral.typeOfColumn.GetDecimal));
                    this.mLoaiChungTu = Conversions.ToString(modGeneral.GetValue(dataReader, 0x25, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienTao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x26, modGeneral.typeOfColumn.GetString));
                    this.mNgayTao = Conversions.ToString(modGeneral.GetValue(dataReader, 0x27, modGeneral.typeOfColumn.GetString));
                    this.mKhoaNhanVienSua = Conversions.ToString(modGeneral.GetValue(dataReader, 40, modGeneral.typeOfColumn.GetString));
                    this.mNgaySua = Conversions.ToString(modGeneral.GetValue(dataReader, 0x29, modGeneral.typeOfColumn.GetString));
                    this.mGhiSo = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x2a, modGeneral.typeOfColumn.GetInt32));
                    this.mKhoaDonVi = Conversions.ToString(modGeneral.GetValue(dataReader, 0x2b, modGeneral.typeOfColumn.GetString));
                    this.mSend = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x2c, modGeneral.typeOfColumn.GetInt32));
                    this.mKhoaNhanVienGiaoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x2d, modGeneral.typeOfColumn.GetString));
                    this.mTinhTrangGiaoHang = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x2e, modGeneral.typeOfColumn.GetInt32));
                    this.mDiaChiGiaoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x2f, modGeneral.typeOfColumn.GetString));
                    this.mDienGiaiGiaoHang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x30, modGeneral.typeOfColumn.GetString));
                    this.mCachTinhChietKhau = Conversions.ToString(modGeneral.GetValue(dataReader, 0x31, modGeneral.typeOfColumn.GetString));
                    this.mTyLeChietKhau = Conversions.ToInteger(modGeneral.GetValue(dataReader, 50, modGeneral.typeOfColumn.GetInt32));
                    this.mTenDoiTuongThue = Conversions.ToString(modGeneral.GetValue(dataReader, 0x33, modGeneral.typeOfColumn.GetString));
                    this.mMaSoThue = Conversions.ToString(modGeneral.GetValue(dataReader, 0x34, modGeneral.typeOfColumn.GetString));
                    this.mDiaChiThue = Conversions.ToString(modGeneral.GetValue(dataReader, 0x35, modGeneral.typeOfColumn.GetString));
                    this.mLoaiBanHang = Conversions.ToString(modGeneral.GetValue(dataReader, 0x36, modGeneral.typeOfColumn.GetString));
                    this.mTienHoaHongNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x37, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienHoaHong = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x38, modGeneral.typeOfColumn.GetDecimal));
                    this.mNghiepVu = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x39, modGeneral.typeOfColumn.GetInt32));
                    this.mThuNgayNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x3a, modGeneral.typeOfColumn.GetDecimal));
                    this.mThuNgay = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x3b, modGeneral.typeOfColumn.GetDecimal));
                    this.mDuLieu = Conversions.ToString(modGeneral.GetValue(dataReader, 60, modGeneral.typeOfColumn.GetString));
                    this.mDuyet = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x3d, modGeneral.typeOfColumn.GetInt32));
                    this.mNgayThuTien = Conversions.ToString(modGeneral.GetValue(dataReader, 0x3e, modGeneral.typeOfColumn.GetString));
                    this.mTienVonNT = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x3f, modGeneral.typeOfColumn.GetDecimal));
                    this.mTienVon = Conversions.ToDouble(modGeneral.GetValue(dataReader, 0x40, modGeneral.typeOfColumn.GetDecimal));
                    this.mKhoaLoaiIn = Conversions.ToString(modGeneral.GetValue(dataReader, 0x41, modGeneral.typeOfColumn.GetString));
                    this.mDaIn = Conversions.ToInteger(modGeneral.GetValue(dataReader, 0x42, modGeneral.typeOfColumn.GetInt32));
                    this.mMauHoaDon = Conversions.ToString(modGeneral.GetValue(dataReader, 0x43, modGeneral.typeOfColumn.GetString));
                    this.mBarCode = Conversions.ToString(modGeneral.GetValue(dataReader, 0x44, modGeneral.typeOfColumn.GetString));
                    this.mHinhThucThanhToan = Conversions.ToString(modGeneral.GetValue(dataReader, 0x45, modGeneral.typeOfColumn.GetString));
                }
                dataReader.Close();
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Registered(string strKhoa, string strKhoaTKThanhToan, string strKhoaTKThue, string strKhoaTKDoanhThu, string strKhoaTKChietKhau)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[8];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaPhieuNhap", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaTKThanhToan", DbType.Int64, ParameterDirection.Input, strKhoaTKThanhToan);
                commandParameters[2] = DBHelper.createParameter("@KhoaTKThue", DbType.Int64, ParameterDirection.Input, strKhoaTKThue);
                commandParameters[3] = DBHelper.createParameter("@KhoaTKDoanhThu", DbType.Int64, ParameterDirection.Input, strKhoaTKDoanhThu);
                commandParameters[4] = DBHelper.createParameter("@KhoaTKChietKhau", DbType.Int64, ParameterDirection.Input, strKhoaTKChietKhau);
                commandParameters[5] = DBHelper.createParameter("@Task", DbType.Int64, ParameterDirection.Input, "+");
                commandParameters[6] = DBHelper.createParameter("@pAmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[7] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_GhiSoXuatKho", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[7].Value, 0, false))
                {
                    if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[6].Value, 0, false))
                    {
                        LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m quỹ!", ""));
                    }
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Save()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[0x48];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaLoaiXuat", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiXuat);
                commandParameters[2] = DBHelper.createParameter("@KhoaKhoanMuc", DbType.Int64, ParameterDirection.Input, this.mKhoaKhoanMuc);
                commandParameters[3] = DBHelper.createParameter("@KhoaDonHang", DbType.Int64, ParameterDirection.Input, this.mKhoaDonHang);
                commandParameters[4] = DBHelper.createParameter("@SoDonHang", DbType.Int64, ParameterDirection.Input, this.mSoDonHang);
                commandParameters[5] = DBHelper.createParameter("@NgayDonHang", DbType.Int64, ParameterDirection.Input, this.mNgayDonHang);
                commandParameters[6] = DBHelper.createParameter("@SoChungTu", DbType.Int64, ParameterDirection.Input, this.mSoChungTu);
                commandParameters[7] = DBHelper.createParameter("@NgayChungTu", DbType.Int64, ParameterDirection.Input, this.mNgayChungTu);
                commandParameters[8] = DBHelper.createParameter("@KhoaDoiTuong", DbType.Int64, ParameterDirection.Input, this.mKhoaDoiTuong);
                commandParameters[9] = DBHelper.createParameter("@KhoaNhanVienBanHang", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienBanHang);
                commandParameters[10] = DBHelper.createParameter("@KhoaLoaiGia", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiGia);
                commandParameters[11] = DBHelper.createParameter("@NguoiGiao", DbType.Int64, ParameterDirection.Input, this.mNguoiGiao);
                commandParameters[12] = DBHelper.createParameter("@KhoaBoPhan", DbType.Int64, ParameterDirection.Input, this.mKhoaBoPhan);
                commandParameters[13] = DBHelper.createParameter("@KhoaSanPham", DbType.Int64, ParameterDirection.Input, this.mKhoaSanPham);
                commandParameters[14] = DBHelper.createParameter("@KhoaHopDong", DbType.Int64, ParameterDirection.Input, this.mKhoaHopDong);
                commandParameters[15] = DBHelper.createParameter("@LoaiTien", DbType.Int64, ParameterDirection.Input, this.mLoaiTien);
                commandParameters[0x10] = DBHelper.createParameter("@TyGia", DbType.Date, ParameterDirection.Input, this.mTyGia);
                commandParameters[0x11] = DBHelper.createParameter("@KhoaLoaiHoaDon", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiHoaDon);
                commandParameters[0x12] = DBHelper.createParameter("@ThueSuat", DbType.Double, ParameterDirection.Input, this.mThueSuat);
                commandParameters[0x13] = DBHelper.createParameter("@SoHoaDon", DbType.Int64, ParameterDirection.Input, this.mSoHoaDon);
                commandParameters[20] = DBHelper.createParameter("@NgayHoaDon", DbType.Int64, ParameterDirection.Input, this.mNgayHoaDon);
                commandParameters[0x15] = DBHelper.createParameter("@SoSeri", DbType.Int64, ParameterDirection.Input, this.mSoSeri);
                commandParameters[0x16] = DBHelper.createParameter("@TienHangNT", DbType.Date, ParameterDirection.Input, this.mTienHangNT);
                commandParameters[0x17] = DBHelper.createParameter("@TienHang", DbType.Date, ParameterDirection.Input, this.mTienHang);
                commandParameters[0x18] = DBHelper.createParameter("@TienChietKhauNT", DbType.Date, ParameterDirection.Input, this.mTienChietKhauNT);
                commandParameters[0x19] = DBHelper.createParameter("@TienChietKhau", DbType.Date, ParameterDirection.Input, this.mTienChietKhau);
                commandParameters[0x1a] = DBHelper.createParameter("@TienThueVATNT", DbType.Date, ParameterDirection.Input, this.mTienThueVATNT);
                commandParameters[0x1b] = DBHelper.createParameter("@TienThueVAT", DbType.Date, ParameterDirection.Input, this.mTienThueVAT);
                commandParameters[0x1c] = DBHelper.createParameter("@KhoaTKThanhToan", DbType.Int64, ParameterDirection.Input, this.mKhoaTKThanhToan);
                commandParameters[0x1d] = DBHelper.createParameter("@KhoaTKThue", DbType.Int64, ParameterDirection.Input, this.mKhoaTKThue);
                commandParameters[30] = DBHelper.createParameter("@KhoaTKDoanhThu", DbType.Int64, ParameterDirection.Input, this.mKhoaTKDoanhThu);
                commandParameters[0x1f] = DBHelper.createParameter("@KhoaTKChietKhau", DbType.Int64, ParameterDirection.Input, this.mKhoaTKChietKhau);
                commandParameters[0x20] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[0x21] = DBHelper.createParameter("@HanThanhToan", DbType.Double, ParameterDirection.Input, this.mHanThanhToan);
                commandParameters[0x22] = DBHelper.createParameter("@NgayThanhToan", DbType.Int64, ParameterDirection.Input, this.mNgayThanhToan);
                commandParameters[0x23] = DBHelper.createParameter("@DaThanhToanNT", DbType.Date, ParameterDirection.Input, this.mDaThanhToanNT);
                commandParameters[0x24] = DBHelper.createParameter("@DaThanhToan", DbType.Date, ParameterDirection.Input, this.mDaThanhToan);
                commandParameters[0x25] = DBHelper.createParameter("@LoaiChungTu", DbType.Int64, ParameterDirection.Input, this.mLoaiChungTu);
                commandParameters[0x26] = DBHelper.createParameter("@KhoaNhanVienTao", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienTao);
                commandParameters[0x27] = DBHelper.createParameter("@NgayTao", DbType.Int64, ParameterDirection.Input, this.mNgayTao);
                commandParameters[40] = DBHelper.createParameter("@KhoaNhanVienSua", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienSua);
                commandParameters[0x29] = DBHelper.createParameter("@NgaySua", DbType.Int64, ParameterDirection.Input, this.mNgaySua);
                commandParameters[0x2a] = DBHelper.createParameter("@GhiSo", DbType.Double, ParameterDirection.Input, this.mGhiSo);
                commandParameters[0x2b] = DBHelper.createParameter("@KhoaDonVi", DbType.Int64, ParameterDirection.Input, this.mKhoaDonVi);
                commandParameters[0x2c] = DBHelper.createParameter("@Send", DbType.Double, ParameterDirection.Input, this.mSend);
                commandParameters[0x2d] = DBHelper.createParameter("@KhoaNhanVienGiaoHang", DbType.Int64, ParameterDirection.Input, this.mKhoaNhanVienGiaoHang);
                commandParameters[0x2e] = DBHelper.createParameter("@TinhTrangGiaoHang", DbType.Double, ParameterDirection.Input, this.mTinhTrangGiaoHang);
                commandParameters[0x2f] = DBHelper.createParameter("@DiaChiGiaoHang", DbType.Int64, ParameterDirection.Input, this.mDiaChiGiaoHang);
                commandParameters[0x30] = DBHelper.createParameter("@DienGiaiGiaoHang", DbType.Int64, ParameterDirection.Input, this.mDienGiaiGiaoHang);
                commandParameters[0x31] = DBHelper.createParameter("@CachTinhChietKhau", DbType.Int64, ParameterDirection.Input, this.mCachTinhChietKhau);
                commandParameters[50] = DBHelper.createParameter("@TyLeChietKhau", DbType.Double, ParameterDirection.Input, this.mTyLeChietKhau);
                commandParameters[0x33] = DBHelper.createParameter("@TenDoiTuongThue", DbType.Int64, ParameterDirection.Input, this.mTenDoiTuongThue);
                commandParameters[0x34] = DBHelper.createParameter("@MaSoThue", DbType.Int64, ParameterDirection.Input, this.mMaSoThue);
                commandParameters[0x35] = DBHelper.createParameter("@DiaChiThue", DbType.Int64, ParameterDirection.Input, this.mDiaChiThue);
                commandParameters[0x36] = DBHelper.createParameter("@LoaiBanHang", DbType.Int64, ParameterDirection.Input, this.mLoaiBanHang);
                commandParameters[0x37] = DBHelper.createParameter("@TienHoaHongNT", DbType.Date, ParameterDirection.Input, this.mTienHoaHongNT);
                commandParameters[0x38] = DBHelper.createParameter("@TienHoaHong", DbType.Date, ParameterDirection.Input, this.mTienHoaHong);
                commandParameters[0x39] = DBHelper.createParameter("@NghiepVu", DbType.Double, ParameterDirection.Input, this.mNghiepVu);
                commandParameters[0x3a] = DBHelper.createParameter("@ThuNgayNT", DbType.Date, ParameterDirection.Input, this.mThuNgayNT);
                commandParameters[0x3b] = DBHelper.createParameter("@ThuNgay", DbType.Date, ParameterDirection.Input, this.mThuNgay);
                commandParameters[60] = DBHelper.createParameter("@DuLieu", DbType.Int64, ParameterDirection.Input, this.mDuLieu);
                commandParameters[0x3d] = DBHelper.createParameter("@Duyet", DbType.Double, ParameterDirection.Input, this.mDuyet);
                commandParameters[0x3e] = DBHelper.createParameter("@NgayThuTien", DbType.Int64, ParameterDirection.Input, this.mNgayThuTien);
                commandParameters[0x3f] = DBHelper.createParameter("@TienVonNT", DbType.Date, ParameterDirection.Input, this.mTienVonNT);
                commandParameters[0x40] = DBHelper.createParameter("@TienVon", DbType.Date, ParameterDirection.Input, this.mTienVon);
                commandParameters[0x41] = DBHelper.createParameter("@KhoaLoaiIn", DbType.Int64, ParameterDirection.Input, this.mKhoaLoaiIn);
                commandParameters[0x42] = DBHelper.createParameter("@DaIn", DbType.Double, ParameterDirection.Input, this.mDaIn);
                commandParameters[0x43] = DBHelper.createParameter("@MauHoaDon", DbType.Int64, ParameterDirection.Input, this.mMauHoaDon);
                commandParameters[0x44] = DBHelper.createParameter("@BarCode", DbType.Int64, ParameterDirection.Input, this.mBarCode);
                commandParameters[0x45] = DBHelper.createParameter("@HinhThucThanhToan", DbType.Int64, ParameterDirection.Input, this.mHinhThucThanhToan);
                commandParameters[70] = DBHelper.createParameter("@AmKho", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[0x47] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_XuatKho", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[0x47].Value, 0, false))
                {
                    return true;
                }
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[70].Value, 0, false))
                {
                    LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m kho!", ""));
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public void SetBlank()
        {
            this.mKhoa = "";
            this.mKhoaLoaiXuat = "";
            this.mKhoaKhoanMuc = "";
            this.mKhoaDonHang = "";
            this.mSoDonHang = "";
            this.mNgayDonHang = "";
            this.mSoChungTu = "";
            this.mNgayChungTu = "";
            this.mKhoaDoiTuong = "";
            this.mKhoaNhanVienBanHang = "";
            this.mKhoaLoaiGia = "";
            this.mNguoiGiao = "";
            this.mKhoaBoPhan = "";
            this.mKhoaSanPham = "";
            this.mKhoaHopDong = "";
            this.mLoaiTien = "";
            this.mTyGia = 0.0;
            this.mKhoaLoaiHoaDon = "";
            this.mThueSuat = 0;
            this.mSoHoaDon = "";
            this.mNgayHoaDon = "";
            this.mSoSeri = "";
            this.mTienHangNT = 0.0;
            this.mTienHang = 0.0;
            this.mTienChietKhauNT = 0.0;
            this.mTienChietKhau = 0.0;
            this.mTienThueVATNT = 0.0;
            this.mTienThueVAT = 0.0;
            this.mKhoaTKThanhToan = "";
            this.mKhoaTKThue = "";
            this.mKhoaTKDoanhThu = "";
            this.mKhoaTKChietKhau = "";
            this.mDienGiai = "";
            this.mHanThanhToan = 0;
            this.mNgayThanhToan = "";
            this.mDaThanhToanNT = 0.0;
            this.mDaThanhToan = 0.0;
            this.mLoaiChungTu = "";
            this.mKhoaNhanVienTao = "";
            this.mNgayTao = "";
            this.mKhoaNhanVienSua = "";
            this.mNgaySua = "";
            this.mGhiSo = 0;
            this.mKhoaDonVi = "";
            this.mSend = 0;
            this.mKhoaNhanVienGiaoHang = "";
            this.mTinhTrangGiaoHang = 0;
            this.mDiaChiGiaoHang = "";
            this.mDienGiaiGiaoHang = "";
            this.mCachTinhChietKhau = "";
            this.mTyLeChietKhau = 0;
            this.mTenDoiTuongThue = "";
            this.mMaSoThue = "";
            this.mDiaChiThue = "";
            this.mLoaiBanHang = "";
            this.mTienHoaHongNT = 0.0;
            this.mTienHoaHong = 0.0;
            this.mNghiepVu = 0;
            this.mThuNgayNT = 0.0;
            this.mThuNgay = 0.0;
            this.mDuLieu = "";
            this.mDuyet = 0;
            this.mNgayThuTien = "";
            this.mTienVonNT = 0.0;
            this.mTienVon = 0.0;
        }

        public string TimKhoaChiTietTheoSoSerial(string strSoserial)
        {
            string commandText = "SELECT Khoa FROM ST_XuatKhoChiTiet WHERE CHARINDEX('" + strSoserial + "',RTRIM(SoSeri)) <> 0";
            return LVYModule.ReturnIfNull(RuntimeHelpers.GetObjectValue(DBHelper.ExecuteScalar(modGeneral.ConnectionString, CommandType.Text, commandText, new IDataParameter[0])), "", modGeneral.TypeOfValue.Nothing).ToString().Trim();
        }

        public bool UnRegistered(string strKhoa)
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[8];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@KhoaPhieuNhap", DbType.Int64, ParameterDirection.Input, strKhoa);
                commandParameters[1] = DBHelper.createParameter("@KhoaTKThanhToan", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[2] = DBHelper.createParameter("@KhoaTKThue", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[3] = DBHelper.createParameter("@KhoaTKDoanhThu", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[4] = DBHelper.createParameter("@KhoaTKChietKhau", DbType.Int64, ParameterDirection.Input, "");
                commandParameters[5] = DBHelper.createParameter("@Task", DbType.Int64, ParameterDirection.Input, "-");
                commandParameters[6] = DBHelper.createParameter("@pAmQuy", DbType.Double, ParameterDirection.Output, 0);
                commandParameters[7] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_GhiSoXuatKho", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[7].Value, 0, false))
                {
                    if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectNotEqual(commandParameters[6].Value, 0, false))
                    {
                        LVYModule.ShowWarning(modGeneral.Tranlated("Nghiệp vụ kh\x00f4ng thể thực hiện được v\x00ec \x00e2m quỹ!", ""));
                    }
                    return false;
                }
                flag = true;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public bool Update()
        {
            bool flag=false;
            IDataParameter[] commandParameters = new IDataParameter[10];
            try
            {
                commandParameters[0] = DBHelper.createParameter("@Khoa", DbType.Int64, ParameterDirection.Input, this.mKhoa);
                commandParameters[1] = DBHelper.createParameter("@MauHoaDon", DbType.Int64, ParameterDirection.Input, this.mMauHoaDon);
                commandParameters[2] = DBHelper.createParameter("@SoSeri", DbType.Int64, ParameterDirection.Input, this.mSoSeri);
                commandParameters[3] = DBHelper.createParameter("@SoHoaDon", DbType.Int64, ParameterDirection.Input, this.mSoHoaDon);
                commandParameters[4] = DBHelper.createParameter("@NgayHoaDon", DbType.Int64, ParameterDirection.Input, this.mNgayHoaDon);
                commandParameters[5] = DBHelper.createParameter("@TenDoiTuongThue", DbType.Int64, ParameterDirection.Input, this.mTenDoiTuongThue);
                commandParameters[6] = DBHelper.createParameter("@MaSoThue", DbType.Int64, ParameterDirection.Input, this.mMaSoThue);
                commandParameters[7] = DBHelper.createParameter("@BarCode", DbType.Int64, ParameterDirection.Input, this.mBarCode);
                commandParameters[8] = DBHelper.createParameter("@DienGiai", DbType.Int64, ParameterDirection.Input, this.mDienGiai);
                commandParameters[9] = DBHelper.createParameter("@pError", DbType.Double, ParameterDirection.Output, 0);
                int num = DBHelper.ExecuteNonQuery(modGeneral.ConnectionString, CommandType.StoredProcedure, "ST_sp_CapNhatXuatKho", commandParameters);
                if (Microsoft.VisualBasic.CompilerServices.Operators.ConditionalCompareObjectEqual(commandParameters[9].Value, 0, false))
                {
                    return true;
                }
                flag = false;
            }
            catch (Exception exception1)
            {
                ProjectData.SetProjectError(exception1);
                Exception exception = exception1;
                MessageBox.Show(exception.Message.ToString());
                flag = false;
                ProjectData.ClearProjectError();
                return flag;
                ProjectData.ClearProjectError();
            }
            return flag;
        }

        public string BarCode
        {
            get
            {
                return this.mBarCode;
            }
            set
            {
                this.mBarCode = value;
            }
        }

        public string CachTinhChietKhau
        {
            get
            {
                return this.mCachTinhChietKhau;
            }
            set
            {
                this.mCachTinhChietKhau = value;
            }
        }

        public int DaIn
        {
            get
            {
                return this.mDaIn;
            }
            set
            {
                this.mDaIn = value;
            }
        }

        public double DaThanhToan
        {
            get
            {
                return this.mDaThanhToan;
            }
            set
            {
                this.mDaThanhToan = value;
            }
        }

        public double DaThanhToanNT
        {
            get
            {
                return this.mDaThanhToanNT;
            }
            set
            {
                this.mDaThanhToanNT = value;
            }
        }

        public string DiaChiGiaoHang
        {
            get
            {
                return this.mDiaChiGiaoHang;
            }
            set
            {
                this.mDiaChiGiaoHang = value;
            }
        }

        public string DiaChiThue
        {
            get
            {
                return this.mDiaChiThue;
            }
            set
            {
                this.mDiaChiThue = value;
            }
        }

        public string DienGiai
        {
            get
            {
                return this.mDienGiai;
            }
            set
            {
                this.mDienGiai = value;
            }
        }

        public string DienGiaiGiaoHang
        {
            get
            {
                return this.mDienGiaiGiaoHang;
            }
            set
            {
                this.mDienGiaiGiaoHang = value;
            }
        }

        public string DuLieu
        {
            get
            {
                return this.mDuLieu;
            }
            set
            {
                this.mDuLieu = value;
            }
        }

        public int Duyet
        {
            get
            {
                return this.mDuyet;
            }
            set
            {
                this.mDuyet = value;
            }
        }

        public int GhiSo
        {
            get
            {
                return this.mGhiSo;
            }
            set
            {
                this.mGhiSo = value;
            }
        }

        public int HanThanhToan
        {
            get
            {
                return this.mHanThanhToan;
            }
            set
            {
                this.mHanThanhToan = value;
            }
        }

        public string HinhThucThanhToan
        {
            get
            {
                return this.mHinhThucThanhToan;
            }
            set
            {
                this.mHinhThucThanhToan = value;
            }
        }

        public string Khoa
        {
            get
            {
                return this.mKhoa;
            }
            set
            {
                this.mKhoa = value;
            }
        }

        public string KhoaBoPhan
        {
            get
            {
                return this.mKhoaBoPhan;
            }
            set
            {
                this.mKhoaBoPhan = value;
            }
        }

        public string KhoaDoiTuong
        {
            get
            {
                return this.mKhoaDoiTuong;
            }
            set
            {
                this.mKhoaDoiTuong = value;
            }
        }

        public string KhoaDonHang
        {
            get
            {
                return this.mKhoaDonHang;
            }
            set
            {
                this.mKhoaDonHang = value;
            }
        }

        public string KhoaDonVi
        {
            get
            {
                return this.mKhoaDonVi;
            }
            set
            {
                this.mKhoaDonVi = value;
            }
        }

        public string KhoaHopDong
        {
            get
            {
                return this.mKhoaHopDong;
            }
            set
            {
                this.mKhoaHopDong = value;
            }
        }

        public string KhoaKhoanMuc
        {
            get
            {
                return this.mKhoaKhoanMuc;
            }
            set
            {
                this.mKhoaKhoanMuc = value;
            }
        }

        public string KhoaLoaiGia
        {
            get
            {
                return this.mKhoaLoaiGia;
            }
            set
            {
                this.mKhoaLoaiGia = value;
            }
        }

        public string KhoaLoaiHoaDon
        {
            get
            {
                return this.mKhoaLoaiHoaDon;
            }
            set
            {
                this.mKhoaLoaiHoaDon = value;
            }
        }

        public string KhoaLoaiIn
        {
            get
            {
                return this.mKhoaLoaiIn;
            }
            set
            {
                this.mKhoaLoaiIn = value;
            }
        }

        public string KhoaLoaiXuat
        {
            get
            {
                return this.mKhoaLoaiXuat;
            }
            set
            {
                this.mKhoaLoaiXuat = value;
            }
        }

        public string KhoaNhanVienBanHang
        {
            get
            {
                return this.mKhoaNhanVienBanHang;
            }
            set
            {
                this.mKhoaNhanVienBanHang = value;
            }
        }

        public string KhoaNhanVienGiaoHang
        {
            get
            {
                return this.mKhoaNhanVienGiaoHang;
            }
            set
            {
                this.mKhoaNhanVienGiaoHang = value;
            }
        }

        public string KhoaNhanVienSua
        {
            get
            {
                return this.mKhoaNhanVienSua;
            }
            set
            {
                this.mKhoaNhanVienSua = value;
            }
        }

        public string KhoaNhanVienTao
        {
            get
            {
                return this.mKhoaNhanVienTao;
            }
            set
            {
                this.mKhoaNhanVienTao = value;
            }
        }

        public string KhoaSanPham
        {
            get
            {
                return this.mKhoaSanPham;
            }
            set
            {
                this.mKhoaSanPham = value;
            }
        }

        public string KhoaTKChietKhau
        {
            get
            {
                return this.mKhoaTKChietKhau;
            }
            set
            {
                this.mKhoaTKChietKhau = value;
            }
        }

        public string KhoaTKDoanhThu
        {
            get
            {
                return this.mKhoaTKDoanhThu;
            }
            set
            {
                this.mKhoaTKDoanhThu = value;
            }
        }

        public string KhoaTKThanhToan
        {
            get
            {
                return this.mKhoaTKThanhToan;
            }
            set
            {
                this.mKhoaTKThanhToan = value;
            }
        }

        public string KhoaTKThue
        {
            get
            {
                return this.mKhoaTKThue;
            }
            set
            {
                this.mKhoaTKThue = value;
            }
        }

        public string LoaiBanHang
        {
            get
            {
                return this.mLoaiBanHang;
            }
            set
            {
                this.mLoaiBanHang = value;
            }
        }

        public string LoaiChungTu
        {
            get
            {
                return this.mLoaiChungTu;
            }
            set
            {
                this.mLoaiChungTu = value;
            }
        }

        public string LoaiTien
        {
            get
            {
                return this.mLoaiTien;
            }
            set
            {
                this.mLoaiTien = value;
            }
        }

        public string MaSoThue
        {
            get
            {
                return this.mMaSoThue;
            }
            set
            {
                this.mMaSoThue = value;
            }
        }

        public string MauHoaDon
        {
            get
            {
                return this.mMauHoaDon;
            }
            set
            {
                this.mMauHoaDon = value;
            }
        }

        public string NgayChungTu
        {
            get
            {
                return this.mNgayChungTu;
            }
            set
            {
                this.mNgayChungTu = value;
            }
        }

        public string NgayDonHang
        {
            get
            {
                return this.mNgayDonHang;
            }
            set
            {
                this.mNgayDonHang = value;
            }
        }

        public string NgayHoaDon
        {
            get
            {
                return this.mNgayHoaDon;
            }
            set
            {
                this.mNgayHoaDon = value;
            }
        }

        public string NgaySua
        {
            get
            {
                return this.mNgaySua;
            }
            set
            {
                this.mNgaySua = value;
            }
        }

        public string NgayTao
        {
            get
            {
                return this.mNgayTao;
            }
            set
            {
                this.mNgayTao = value;
            }
        }

        public string NgayThanhToan
        {
            get
            {
                return this.mNgayThanhToan;
            }
            set
            {
                this.mNgayThanhToan = value;
            }
        }

        public string NgayThuTien
        {
            get
            {
                return this.mNgayThuTien;
            }
            set
            {
                this.mNgayThuTien = value;
            }
        }

        public int NghiepVu
        {
            get
            {
                return this.mNghiepVu;
            }
            set
            {
                this.mNghiepVu = value;
            }
        }

        public string NguoiGiao
        {
            get
            {
                return this.mNguoiGiao;
            }
            set
            {
                this.mNguoiGiao = value;
            }
        }

        public int Send
        {
            get
            {
                return this.mSend;
            }
            set
            {
                this.mSend = value;
            }
        }

        public string SoChungTu
        {
            get
            {
                return this.mSoChungTu;
            }
            set
            {
                this.mSoChungTu = value;
            }
        }

        public string SoDonHang
        {
            get
            {
                return this.mSoDonHang;
            }
            set
            {
                this.mSoDonHang = value;
            }
        }

        public string SoHoaDon
        {
            get
            {
                return this.mSoHoaDon;
            }
            set
            {
                this.mSoHoaDon = value;
            }
        }

        public string SoSeri
        {
            get
            {
                return this.mSoSeri;
            }
            set
            {
                this.mSoSeri = value;
            }
        }

        public string TenDoiTuongThue
        {
            get
            {
                return this.mTenDoiTuongThue;
            }
            set
            {
                this.mTenDoiTuongThue = value;
            }
        }

        public int ThueSuat
        {
            get
            {
                return this.mThueSuat;
            }
            set
            {
                this.mThueSuat = value;
            }
        }

        public double ThuNgay
        {
            get
            {
                return this.mThuNgay;
            }
            set
            {
                this.mThuNgay = value;
            }
        }

        public double ThuNgayNT
        {
            get
            {
                return this.mThuNgayNT;
            }
            set
            {
                this.mThuNgayNT = value;
            }
        }

        public double TienChietKhau
        {
            get
            {
                return this.mTienChietKhau;
            }
            set
            {
                this.mTienChietKhau = value;
            }
        }

        public double TienChietKhauNT
        {
            get
            {
                return this.mTienChietKhauNT;
            }
            set
            {
                this.mTienChietKhauNT = value;
            }
        }

        public double TienHang
        {
            get
            {
                return this.mTienHang;
            }
            set
            {
                this.mTienHang = value;
            }
        }

        public double TienHangNT
        {
            get
            {
                return this.mTienHangNT;
            }
            set
            {
                this.mTienHangNT = value;
            }
        }

        public double TienHoaHong
        {
            get
            {
                return this.mTienHoaHong;
            }
            set
            {
                this.mTienHoaHong = value;
            }
        }

        public double TienHoaHongNT
        {
            get
            {
                return this.mTienHoaHongNT;
            }
            set
            {
                this.mTienHoaHongNT = value;
            }
        }

        public double TienThueVAT
        {
            get
            {
                return this.mTienThueVAT;
            }
            set
            {
                this.mTienThueVAT = value;
            }
        }

        public double TienThueVATNT
        {
            get
            {
                return this.mTienThueVATNT;
            }
            set
            {
                this.mTienThueVATNT = value;
            }
        }

        public double TienVon
        {
            get
            {
                return this.mTienVon;
            }
            set
            {
                this.mTienVon = value;
            }
        }

        public double TienVonNT
        {
            get
            {
                return this.mTienVonNT;
            }
            set
            {
                this.mTienVonNT = value;
            }
        }

        public int TinhTrangGiaoHang
        {
            get
            {
                return this.mTinhTrangGiaoHang;
            }
            set
            {
                this.mTinhTrangGiaoHang = value;
            }
        }

        public double TyGia
        {
            get
            {
                return this.mTyGia;
            }
            set
            {
                this.mTyGia = value;
            }
        }

        public int TyLeChietKhau
        {
            get
            {
                return this.mTyLeChietKhau;
            }
            set
            {
                this.mTyLeChietKhau = value;
            }
        }
    }
}

